package rhc.discribute.node.connecter.schedule;

import java.util.concurrent.CountDownLatch;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import rhc.discribute.BaseComponent;
import rhc.discribute.node.connecter.impl.ZKPathLockData;
import rhc.discribute.node.connecter.impl.zookper.ZookperLockImpl;
import rhc.discribute.util.ScheduleUpdate;

public class LockPathJob extends BaseComponent implements Job {

	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		//在创建任务时会将本对象绑定到任务
		JobDataMap jobDataMap=arg0.getMergedJobDataMap();
		
		LockPathSchedule schedule=(LockPathSchedule) jobDataMap.get(ScheduleUpdate.SCHEDULE_UPDATE);
		
		ZookperLockImpl zkLock=schedule.getZkLock();
		CountDownLatch latch=schedule.getLatch();
		ZKPathLockData zkPLD=schedule.getZkPLD();
		
		try{
			if(null != latch){
				latch.countDown();
			}
			zkLock.release(zkPLD);
		} catch (Exception e) {
			
		}finally{
			logger.debug("定时释放锁任务触发");
			schedule.clear();
		}
	}

}
